/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase2203 - VolatileDemo
 * <p>Powered by webrx On 2022-08-09 09:38:29
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class VolatileDemo {
    volatile boolean f = true;
    void m(){
        String t = Thread.currentThread().getName();
        System.out.printf("%s线程启动...%n",t);
        while(f){

        }
        System.out.printf("%s线程结束...%n",t);
    }
    public static void main(String[] args) {
        var t = new VolatileDemo();

        new Thread(t::m,"TT1").start();

        //main
        try{
            TimeUnit.SECONDS.sleep(2);
        }catch(Exception e){
            e.printStackTrace();
        }
        t.f = false;
        System.out.println(t.f);
    }
}
